package zucc.lcj.android_finalwork.guide;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;

import zucc.lcj.android_finalwork.FriendsActivity;
import zucc.lcj.android_finalwork.help.HelpActivity;
import zucc.lcj.android_finalwork.R;
import zucc.lcj.android_finalwork.stars.StarsActivity;
import zucc.lcj.android_finalwork.me.MeActivity;

public class GuideActivity extends AppCompatActivity {
    private Banner mBanner;
    private LocalImageLoader mImageLoader;
    private ArrayList<Integer> imagePath;
    private ArrayList<String> imageTitle;
    Button mapBtm;
    Button birdBtm;
    Button foodBtm;
    Button printBtm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
//        导航栏
        ImageView bar_1 = (ImageView) findViewById(R.id.bar_1);
        ImageView bar_2 = (ImageView) findViewById(R.id.bar_2);
        ImageView bar_3 = (ImageView) findViewById(R.id.bar_3);
        ImageView bar_4 = (ImageView) findViewById(R.id.bar_4);
        ImageView bar_5 = (ImageView) findViewById(R.id.bar_5);
        bar_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this, FriendsActivity.class);
                startActivity(intent);
            }
        });
        bar_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this, HelpActivity.class);
                startActivity(intent);
            }
        });
        bar_5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this,MeActivity.class);
                startActivity(intent);
            }
        });
        bar_4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this, StarsActivity.class);
                startActivity(intent);
            }
        });
//        轮播
        mBanner = findViewById(R.id.me_more4_banner);
        intDate();
        intView();
//        点击详情
//        学校地图详情
        mapBtm = (Button) findViewById(R.id.guide_map_btm);
        mapBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this,MapActivity.class);
                startActivity(intent);
            }
        });
//        学校快递站点详情
        birdBtm = (Button) findViewById(R.id.guide_bird_btm);
        birdBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this,ExpressActivity.class);
                startActivity(intent);
            }
        });
//        学校美食详情
        foodBtm = (Button) findViewById(R.id.guide_food_btm);
        foodBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this,FoodActivity.class);
                startActivity(intent);
            }
        });
//        学校打印店详情
        printBtm = (Button) findViewById(R.id.guide_print_btm);
        printBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this,PrintActivity.class);
                startActivity(intent);
            }
        });

    }

    private void intDate() {
        imagePath = new ArrayList<>();
        imageTitle = new ArrayList<>();
        imagePath.add(R.drawable.me_more4_lunbo1);
        imagePath.add(R.drawable.me_more4_lunbo2);
        imagePath.add(R.drawable.me_more4_lunbo3);
        imagePath.add(R.drawable.me_more4_lunbo4);
        imagePath.add(R.drawable.me_more4_lunbo5);
        imageTitle.add("第一");
        imageTitle.add("第二");
        imageTitle.add("第三");
        imageTitle.add("第四");
        imageTitle.add("第五");
    }

    private void intView() {
        mImageLoader = new LocalImageLoader();
        mBanner = findViewById(R.id.me_more4_banner);
        //样式
        //banner无标题样式
        mBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //加载器
        mBanner.setImageLoader(mImageLoader);
        //动画效果
        mBanner.setBannerAnimation(Transformer.ZoomOutSlide);
        //图片标题
        mBanner.setBannerTitles(imageTitle);
        //间隔时间
        mBanner.setDelayTime(3000);
        //是否为自动轮播
        mBanner.isAutoPlay(true);
        //图片小点显示所在位置
        mBanner.setIndicatorGravity(BannerConfig.CENTER);
        //图片加载地址
        mBanner.setImages(imagePath);
        //启动轮播图。
        mBanner.start();
        //监听轮播图
        mBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                Toast.makeText(GuideActivity.this, "点击了" + (position + 1) + "张轮播图", Toast.LENGTH_SHORT).show();
            }
        });
    }
    /**
     * 图片加载类
     */
    private class LocalImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context.getApplicationContext())
                    .load(path)
                    .into(imageView);
        }
    }
}

